package cn.jiaqiang.chatgpt.data.infrastructure.repository;

import cn.jiaqiang.chatgpt.data.domain.auth.repository.IAuthRepository;
import cn.jiaqiang.chatgpt.data.infrastructure.redis.IRedisService;
import cn.jiaqiang.chatgpt.data.types.common.RedisConstants;
import org.checkerframework.checker.units.qual.K;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * @description 认证仓储服务
 */
@Repository
public class AuthRepository implements IAuthRepository {

    private static final String Key = RedisConstants.OPENAI_CODE_PREFIX;
    private static final String Separator = RedisConstants.SEPARATOR;

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public String getOpenIdByUserCode(String code) {
        return stringRedisTemplate.opsForValue().get(Key + Separator + code);
    }

    @Override
    public void removeCodeAndUserId(String code, String userId, String openId) {
        stringRedisTemplate.delete(Key + Separator + userId);
        stringRedisTemplate.delete(Key + Separator + openId);
        stringRedisTemplate.delete(Key + Separator + code);
    }

    @Override
    public String getRedisCodeByUSerId(String userId) {
        return stringRedisTemplate.opsForValue().get(Key + Separator + userId);

    }

    @Override
    public String getUserIdByOpenId(String openId) {
        return stringRedisTemplate.opsForValue().get(Key + Separator + openId);
    }


}
